<template>
	<div style="padding:0px;">
		<el-form :model="dialogForm" :rules="rules" ref="dialogForm"  :label-width="formLabelWidth">
			<el-card class="box-card">
			  <div slot="header" class="clearfix">
			    <span style="line-height: 30px;">品牌信息</span>
			  </div>
			  <div  class="text item">
				  
				  <el-form-item label="汽车品牌"  prop="carBrandId"> 
        	     <el-select v-model.number="dialogForm.carBrandId" filterable  placeholder="汽车品牌"   :disabled="!dialogSendData.isAdd"   > 
		         <el-option  v-for="(item,index) in selectCarBrandModel"  :label="item.name"  :value="item.id"  :key="index" >  
                 </el-option>  
		         </el-select>
	            </el-form-item>
				    <el-form-item label="排序" prop="rank">
				      <el-input v-model.number="dialogForm.rank" :maxlength="9" auto-complete="off" :disabled="!dialogSendData.isAdd"></el-input>
				    </el-form-item>
				    <el-form-item label="时间"  v-if="!dialogSendData.isAdd">
				      <el-input :value="dialogForm.addDate|parseTime" auto-complete="off"  disabled></el-input>
				    </el-form-item>
				    
				  
				</div>
			</el-card>
		</el-form>
		<div style="text-align:right;margin-top:15px;">
			 <el-button @click="returnBack">返 回</el-button>
			 <el-button v-if="dialogSendData.isAdd" type="primary" @click="submitConfirmForm('dialogForm')">提 交</el-button>
		</div>
	</div>
</template>
<script>
    import agentHttp from '@/utils/agentHttp.js'
    import {require,decimal} from '@/utils/rules.js'
	export default{
		created(){
			this.getSelectCarBrandModel();
   			if(this.dialogSendData.id!==""){
	      		this.selectData();//修改      	    
	      	}else{	      		
	      		//console.log('新增')
	      	}
        },
		props:['dialogSendData','tableData'],
		data(){
			return{
				formLabelWidth:'170px',
				//弹窗或者查看页面信息
		        dialogForm:{
		        	carBrandId:"",     	
		        	rank:"",

		        	 //品牌list
				
		        },
		         rules: {
                  'carBrandId':[require('汽车品牌',{trigger:"change",type:"number"})],
		          'rank':[require('排序',{trigger:"blur",type:"number"}),{ validator: decimal, trigger: "change" }]
		        },
		        selectCarBrandModel:[],
		        
			}
		},methods:{
			returnBack(){
				this.dialogSendData.dialogFormVisible=false;
			},
			submitConfirmForm(formName){				
                this.$refs[formName].validate((valid) => {
		          if (valid) {
		          	if(this.dialogSendData.id===""){
		          		this.addData()//添加
		          	}else{		          		
		          		this.editData();//修改
		          	}
		          	
		          } else {
		            this.$nextTick(()=>{
		          	   setTimeout(()=>{this.$message.warning(document.getElementsByClassName('el-form-item__error')[0].innerText);},500) 
		               return false;
		            })
		            return false;
		          }
		        });
			},
			addData(){
		        //this.dialogForm.imagUrl=this.qiniuImage.image_uri.join(",")
		        agentHttp.postJson('adminApi/admin/car_hot_brand/post_validated',this.dialogForm).then((data)=>{
		            if(data.success){  
		            	this.$emit('refreshSeachData', null);
		            	this.$message.success(data.data||"添加成功");
		            	setTimeout(()=>{
		          		this.dialogSendData.dialogFormVisible=false;
		            	},500)
		            } 
		        }) 
		      },
			editData(){
		        agentHttp.putJson('adminApi/admin/car_hot_brand/put_validated',this.dialogForm).then((data)=>{
		            if(data.success){  
		            	this.$emit('refreshSeachData', null);
		            	this.$message.success(data.data||"修改成功");
		            	setTimeout(()=>{
		          		this.dialogSendData.dialogFormVisible=false;
		             	},500)
		            } 
		        }) 
		    },
		    selectData(){
		        agentHttp.get('adminApi/admin/car_hot_brand/select_brand/'+this.dialogSendData.id).then((data)=>{	
		            if(data.success){
						this.dialogForm=data.data;
						
		            } 
		        }) 
		    },
		     getSelectCarBrandModel(){  
	    		agentHttp.get('adminApi/admin/dictionary/find_all_car_brand').then((data)=>{
		            if(data.success){ 
		              //品牌
		              this.selectCarBrandModel =  data.data;  
		            } 
		        })
		    },
		    
		}
	};
	
</script>